#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
extern char** environ;//需要声明 指向 存放全局变量的字符串指针 的数组
int main()
{
  pid_t id=fork();
  if(id==0)
  {
    //putenv("MY_VAL=888666");//自己导然后传给孩
    //child
    printf("before running pid=%d,ppid=%d\n",getpid(),getppid());
    //系统调用接口，程序替换
    //execle("./otherExe","otherEXE","-a","-b","-c",NULL,environ);//程序路径（哪个程序），怎么执行，可变参数列表（必须NULL结尾），全局变量
    //execl("./otherExe","otherExe","-a","-b","-c",NULL);
   // execl("/usr/bin/bash","bash","test.sh",NULL);
   char*const myevn[]=
   {
     "MY_VALUE1=999",
     "MY_VALUE2=888",
     "MY_VALUE3=777",
     NULL//记得NULL结尾
   };
   execle("./otherExe","otherExe","-a","-w","-s",NULL,myevn);
    printf("after running pid=%d,ppid=%d\n",getpid(),getppid());
    exit(0);//子进程运行完后终止掉程序
  }
  //sleep(5);//让父进程休眠5秒
  pid_t ret_id=waitpid(id,NULL,0);
  if(ret_id>0)
  {
    printf("wait success!! pid=:%d,ppid=:%d\n",getpid(),getppid());
  }
  sleep(5);
  return 0;
}
